const Joi = require('joi');

const roleEnum = ['admin', 'project_admin', 'project_user', 'viewer'];

// 与全局 validate 中间件保持一致：直接导出 Joi 对象（验证 req.body）
const createUser = Joi.object({
  username: Joi.string().min(3).max(30).required(),
  email: Joi.string().email().required(),
  password: Joi.string().min(6).required(),
  role: Joi.string().valid(...roleEnum).required(),
  isActive: Joi.boolean().default(true)
});

const updateUser = Joi.object({
  username: Joi.string().min(3).max(30).optional(),
  email: Joi.string().email().optional(),
  role: Joi.string().valid(...roleEnum).optional(),
  isActive: Joi.boolean().optional()
});

const updateStatus = Joi.object({
  isActive: Joi.boolean().required()
});

const resetPassword = Joi.object({
  newPassword: Joi.string().min(6).required()
});

module.exports = { createUser, updateUser, updateStatus, resetPassword };


